//
//  GYMineOrderInfoSignalVC.m
//  GYDemo
//
//  Created by mac on 2018/4/2.
//  Copyright © 2018年 mac. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "GYMineOrderInfoSignalVC.h"
#import "Head.h"

@interface GYMineOrderInfoSignalVC ()
{
    NSInteger currentPage;
}
@end

@implementation GYMineOrderInfoSignalVC
-(GYMineOrderInfoViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [GYMineOrderInfoViewModel new];
        currentPage = 1;
    }
    return _viewModel;
}
#pragma mark - event
-(void)orderTap:(UITapGestureRecognizer *)gesture
{
    
}
#pragma mark - method
-(void)initilization
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.navigationController.navigationBar.shadowImage = [[UIImage new]rt_darkenWithLevel:0.3f];
    [self setNavgationTheme:1];
    self.isGroup = YES;
    [self.view addSubview:self.baseTable];
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    [self.baseTable setSeparatorColor: Main_Color_BG];
    [self.baseTable setBackgroundColor:Main_Color_BG];
    [self.baseTable setTintColor:Main_Color_BG];
    self.baseTable.height = WF_SCREEN_HEIGHT - self.topShelterHeight - self.bottomShelterHeight;
    
    @WeakSelf;
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        currentPage = 1;
        [selfp reloadData];
    }];
    self.baseTable.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
        currentPage += 1;
        [selfp reloadData];
    }];
    [self viewModelBand];
    
    if (0 == self.viewModel.orderType.integerValue) {
        [self reloadData];
    }
    
    [self reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;
    GCBaseObservationModel *observation = [GCBaseObservationModel new];
    observation.observation = self.viewModel;
    observation.keyPath = @"datas";
    observation.handler = ^(NSString *keyPath) {
        [selfp reloadView];
    };
    [self registObservation:observation];
}
-(void)reloadView
{
    [self.baseTable reloadData];
}
-(void)reloadData
{
    NSMutableDictionary *para = [NSMutableDictionary new];
    [para setObject:_viewModel.orderType forKey:@"status"];
    [self.viewModel requestDatas:para];
}
-(void)reloadFresh
{
    currentPage = 1;
    [self reloadData];
}
#pragma mark - life
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.viewModel.datas.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
//    GYMineOrderInfoModel *info = self.viewModel.datas[section];
//    NSArray *items = info.odlist;
//    return items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellID = @"CellID";
//    GYMineOrderInfoModel *info = self.viewModel.datas[indexPath.section];
//    NSArray *items = info.odlist;
//    NSDictionary *dic = items[indexPath.row];
//    GYMineOrderInfoListModel *model = [GYMineOrderInfoListModel yy_modelWithJSON:dic];
    GYMineOrderInfoListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[GYMineOrderInfoListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
    }
    cell.model = self.viewModel.datas[indexPath.section];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = [GYMineOrderInfoListCell finalHeight];
    return height;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIImageView *view = [UIImageView new];
    view.width = self.view.width;
    view.height = WFCGFloatY(45);
    view.backgroundColor = Main_Color_White;
    view.userInteractionEnabled = YES;
    
    UIView *sign = [UIView new];
    sign.backgroundColor = Main_Color_Red;
    sign.frame = WFCGRectMake(13, 16.5, 5, 15);
    sign.centerY = view.centerY;
    [view addSubview:sign];
    
    UILabel *titlelb = [UILabel new];
    titlelb.x = WFCGFloatX(23);
    titlelb.width = self.view.width - WFCGFloatX(26);
    titlelb.height = WFCGFloatY(34);
    titlelb.centerY = view.centerY;
    titlelb.font = SYSTEMFONT(15);
    titlelb.textColor = Main_Color_Black;
    //GYMineOrderInfoModel *info = self.viewModel.datas[section];
    titlelb.text = @"革优小店";
    [view addSubview:titlelb];
    
    UIButton *phonenumbtn = [UIButton new];
    phonenumbtn.x = WFCGFloatX(234);
    phonenumbtn.width = WFCGFloatX(100);
    phonenumbtn.height = WFCGFloatX(16.5);
    phonenumbtn.centerY = view.centerY;
    phonenumbtn.titleLabel.font = SYSTEMFONT(12);
    [phonenumbtn setTitle:@"400-800-6988" forState:UIControlStateNormal];
    [phonenumbtn setTitleColor:Main_Color_Gray forState:UIControlStateNormal];
    [phonenumbtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        [[GCPresenter shareInterface]phoneCall:@"400-800-6988"];
    }];
    [phonenumbtn setEnlargeEdge:10];
    [view addSubview:phonenumbtn];
    
    UIButton *phonesign = [UIButton new];
    phonesign.x = WFCGFloatX(340);
    phonesign.width = WFCGFloatX(14.5);
    phonesign.height = WFCGFloatX(14.5);
    phonesign.centerY = view.centerY;
    [phonesign setBackgroundImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];
    //phonesign.backgroundColor = Main_Color_Blue;
    [phonesign handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        [[GCPresenter shareInterface]phoneCall:@"400-800-6988"];
    }];
    [phonesign setEnlargeEdge:10];
    [view addSubview:phonesign];
    @WeakSelf;
    [view addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
//        GYMineOrderInfoDetailVC *detail = [GYMineOrderInfoDetailVC new];
//        detail.signalVC = selfp;
//        detail.orderInfoModel = info;
//        detail.orderCatagery = self.viewModel.orderCatagery;
//        [selfp.navigationController pushViewController:detail animated:YES];
    }];
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return WFCGFloatY(44.5);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [UIView new];
    view.width = self.view.width;
    view.height = WFCGFloatY(53);
    view.backgroundColor = Main_Color_White;
    
    UILabel *statelb = [UILabel new];
    statelb.x = WFCGFloatX(13);
    statelb.y = WFCGFloatY(12.5);
    statelb.width = WFCGFloatX(126);
    statelb.height = WFCGFloatY(20);
    statelb.font = SYSTEMFONT(14);
    statelb.textColor = Main_Color_Yellow;
    GYMineOrderInfoListModel *info = self.viewModel.datas[section];
    statelb.text = @"已下单";
    [view addSubview:statelb];
    
    UILabel *totallb = [UILabel new];
    totallb.x = self.view.width - WFCGFloatX(200 + 13);
    totallb.width = WFCGFloatX(200);
    totallb.y = WFCGFloatY(12.5);
    totallb.height = WFCGFloatY(20);
    totallb.font = SYSTEMFONT(14);
    totallb.textColor = Main_Color_Black;
    totallb.textAlignment = NSTextAlignmentRight;
    totallb.text = [NSString stringWithFormat:@"总价：%ld元",info.price];
    [view addSubview:totallb];
    
    UIView *sep = [UIView new];
    sep.width = self.view.width;
    sep.height = 5.0f;
    sep.backgroundColor = Main_Color_BG;
    sep.y = view.height - sep.height;
    [view addSubview:sep];
    @WeakSelf;
    [view addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
//        GYMineOrderInfoDetailVC *detail = [GYMineOrderInfoDetailVC new];
//        detail.signalVC = selfp;
//        detail.orderInfoModel = info;
//        detail.orderCatagery = self.viewModel.orderCatagery;
//        UINavigationController *nav = selfp.navigationController;
////        [selfp.navigationController pushViewController:detail animated:YES];
//        [nav pushViewController:detail animated:YES];
    }];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return WFCGFloatY(53);
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    GYMineOrderInfoModel *info = self.viewModel.datas[indexPath.section];
//    NSArray *items = info.odlist;
//    NSDictionary *dic = items[indexPath.row];
//    GYMineOrderInfoListModel *model = [GYMineOrderInfoListModel yy_modelWithJSON:dic];
//    GYHomeSaleDetailVC *detail = [[GYHomeSaleDetailVC alloc] init];
//    detail.passID = [NSString stringWithFormat:@"%ld",model.proid];
//    [self.navigationController pushViewController:detail animated:YES];
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
